﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BAL;
using System.Data.OleDb;
namespace Giao_dien__1
{
    public partial class FrmDangNhap : Form
    {
        public FrmDangNhap()
        {
            InitializeComponent();
        }
        public BAL.BAL bussi= new BAL.BAL();
        public DataAccess.DAL dal = new DataAccess.DAL();
        private void button1_Click(object sender, EventArgs e)
        {
            OleDbDataReader reader = bussi.Reader("select Pass from accout1 where Id='" + txtUsername.Text + "'");   
            string pass = "";
            try
            {
                
                pass = reader.GetValue(0).ToString();
                int i = pass.IndexOf(' ');
                pass = pass.Substring(0, i);
                if (pass==txtPassWord.Text)
                {
                    MessageBox.Show("Bạn đã đăng nhập thành công!", "Thành công");
                    reader.Close();
                    //con.Close(); 
                    foreach (Form f in Application.OpenForms)
                    {
                        if (f.Name == "FrmChinh")
                            f.Enabled = true;
                        f.Show();
                    }
                    this.Close();
                   
                }     
                else
                    {
                    MessageBox.Show("Sai Mật Khẩu");
                    txtPassWord.Focus();
                    }
                        reader.Close();
                
            }catch
                {
                    MessageBox.Show("Tài Khoảng không đúng");
                    txtPassWord.Focus();
                }
                reader.Close();
            }
            
            


        private void FrmDangNhap_Load(object sender, EventArgs e)
        {
           
        }

        private void FrmDangNhap_FormClosing(object sender, FormClosingEventArgs e)
        {
                       
        }
    }
}
